package org.alex.samples.model;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
//import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;

//import org.hibernate.annotations.Cascade;
import org.hibernate.validator.constraints.NotEmpty;
import org.springframework.format.annotation.DateTimeFormat;
import javax.persistence.JoinColumn;

@Entity
@Table(name="exam_user")
public class UserJDBC implements Serializable {
	private static final long serialVersionUID=-8694539773273501319L;
	
	@Id
	//@GeneratedValue
	@Column(name="user_id" ,nullable=false)
	@NotNull(message="ID不可以为空！")
	private String userId;
	
	@Column(name="user_name" ,length=1000, nullable=false)
	@NotEmpty(message="姓名不可以为空！")
	private String userName;
	
	@Column(name="password" ,length=1000, nullable=false)
	private String password;
	
	@Column(name="tel" ,length=1000, nullable=false)
	private String tel;	
	
	@Column(name="email" ,length=1000, nullable=false)
	private String email;
	
	@Column(name="address" ,length=1000, nullable=false)
	private String address;
	
	@Column(name="birthday" ,length=1000, nullable=false)
	@DateTimeFormat( pattern = "yyyy-MM-dd" )
	private Date birthday;
	
	@Column(name="gender" ,length=1000, nullable=false)
	private int gender;
	
	@Column(name="last_lock_time" ,length=1000, nullable=false)
	private Timestamp lastLockTime;	
	
	@Column(name="login_fail_count" ,length=1000, nullable=false)
	private int loginFailCount;
	
	//指定多对多关系,并设置级联关系
	@ManyToMany(cascade={CascadeType.DETACH,CascadeType.PERSIST,CascadeType.MERGE,CascadeType.ALL})    
	@JoinTable(name="exam_user_subject",                           //中间表的名称
		joinColumns={@JoinColumn(name="user_id")},				   //本表与中间表的外键对应关系
		inverseJoinColumns={@JoinColumn(name="sub_id")})		   //另一张表与中间表的外键的对应关系
	private Set<ExamSubject> examSubject=new HashSet<ExamSubject>();
	
	@ManyToMany(cascade={CascadeType.DETACH,CascadeType.PERSIST,CascadeType.MERGE,CascadeType.ALL}) 
	@JoinTable(name="exam_user_role",                           //中间表的名称
			joinColumns={@JoinColumn(name="user_id")},				   //本表与中间表的外键对应关系
			inverseJoinColumns={@JoinColumn(name="role_id")})		   //另一张表与中间表的外键的对应关系
	private Set<ExamRole> examRole =new HashSet<ExamRole>();
	
		
	public UserJDBC() {
		super();
	}
	
	public String getUserId() {
		return userId;
	}
	public void setUserId(String userId) {
		this.userId = userId;
	}
	public String getUserName() {
		return userName;
	}
	public void setUserName(String userName) {
		this.userName = userName;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public String getTel() {
		return tel;
	}
	public void setTel(String tel) {
		this.tel = tel;
	}
	public String getEmail() {
		return email;
	}
	public void setEmail(String email) {
		this.email = email;
	}
	public String getAddress() {
		return address;
	}
	public void setAddress(String address) {
		this.address = address;
	}
	public Date getBirthday() {
		return birthday;
	}
	public void setBirthday(Date birthday) {
		this.birthday = birthday;
	}
	public int getGender() {
		return gender;
	}
	public void setGender(int gender) {
		this.gender = gender;
	}

	
	
	public Timestamp getLastLockTime() {
		return lastLockTime;
	}

	public void setLastLockTime(Timestamp lastLockTime) {
		this.lastLockTime = lastLockTime;
	}

	public int getLoginFailCount() {
		return loginFailCount;
	}
	public void setLoginFailCount(int loginFailCount) {
		this.loginFailCount = loginFailCount;
	}
	public static long getSerialversionuid() {
		return serialVersionUID;
	}

	
	public Set<ExamSubject> getExamSubject() {
		return examSubject;
	}

	public void setExamSubject(Set<ExamSubject> examSubject) {
		this.examSubject = examSubject;
	}

	public Set<ExamRole> getExamRole() {
		return examRole;
	}

	public void setExamRole(Set<ExamRole> examRole) {
		this.examRole = examRole;
	}
	
	
	
	
	
	
}
